package controllers

import java.util.UUID
import javax.inject.Inject

import models.User
import org.joda.time.DateTime
import services.UserMongoService
import play.api.libs.concurrent.Execution.Implicits.defaultContext
import play.api.mvc._
import play.api.libs.json._
import play.api.libs.functional.syntax._

/**
  * Created by xiaofei on 2016/8/17.
  */
class UserController @Inject()(val myservice: UserMongoService)
  extends CRUDController[User, UUID](myservice)(routes.UserController.read) {

  /*  implicit val UserReaders: Reads[User] = (
      (JsPath \ "uuid").read[UUID] and
        (JsPath \ "name").read[String] and
        (JsPath \ "passwd").read[String] and
        (JsPath \ "email").read[String]
      )(User.apply(_))*/

/*  override def create = Action.async(parse.json) { implicit request =>

    val user1 = request.body.asOpt[User].getOrElse("Type error")
    val user = user1.copy(user1.uuid, user1.name, user1.passwd, user1.email, false, Some(new DateTime()), Some(new DateTime()))
    service.create(user).map {
      case Right(id) => Created.withHeaders(LOCATION -> s"/users/$id")
      case Left(err) => BadRequest(err)
    }

  }*/

}
